package com.xiao.sulinguser.service.impl;

import com.xiao.sulinguser.entity.MemberEntity;
import com.xiao.sulinguser.service.LoginService;
import com.xiao.sulinguser.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

/**
 * @author: 1322127758@qq.com
 * @date: 2022/3/13 21:22
 * @作用:
 */
@Service("loginService")
public class LoginServiceImpl implements LoginService {
    @Autowired
    private MemberService memberService;

    /**
     * 登入验证
     * @param userName :账号
     * @param password :密码
     * @return
     */
    @Override
    public MemberEntity verify(String userName, String password) {
        //1.获取用户信息
        MemberEntity memberEntity = memberService.selectUser(null, userName);
        if(null != memberEntity){
            //2.验证密码
            String MDPassword = memberEntity.getPassword();
            BCryptPasswordEncoder md5 = new BCryptPasswordEncoder();
            boolean matches = md5.matches(password, MDPassword);
            //返回true表示密码一致
            if(matches){
                memberEntity.setPassword("");
                return memberEntity;
            }
        }
        return null;
    }
}
